package fournitures;

public class Packet implements java.io.Serializable {

    /* This class represents a packet that can be sent by the
       PeerServer in response to an encoded download command from the
       PeerClient. The packet contains an integer representing the
       header, i.e. the index of the packet within the superblock, and
       also a byte array. If the packet is null, it signals end of
       transmission of the superblock. */

	private static final long serialVersionUID = 6535754474298337373L;
	private int header;
    private byte[] bytes;

    Packet () {
    }

    public Packet (int header, byte[] bytes) {
        this.header = header;
        this.bytes = bytes;
    }

    public String toString () {
        String s; 
        if (bytes != null) {
            int l = bytes.length;
            s = "Packet with header " + header + " and " + l + " bytes";
        }
        else 
            s = "Packet with header " + header + " and a byte array that is null";
        return s;
    }    
    
    public int getHeader(){
    	
    	return this.header;
    }
    
    public byte[] getData(){
    	
    	return this.bytes;
    }
    
    public void setHeader(int h){
    	
    	this.header=h;
    }
}
